const favoriteModel = require('../models/favoriteModel');

const getFavorites = async (req, res) => {
    try {
        const userId = req.user.id;
        const favorites = await favoriteModel.getFavoritesByUserId(userId);
        res.json(favorites);
    } catch (error) {
        res.status(500).json({ error: '获取收藏列表失败' });
    }
};

const addFavorite = async (req, res) => {
    try {
        const userId = req.user.id;
        const gameId = req.params.id;
        await favoriteModel.addFavorite(userId, gameId);
        res.json({ message: '添加收藏成功' });
    } catch (error) {
        res.status(500).json({ error: '添加收藏失败' });
    }
};

const removeFavorite = async (req, res) => {
    try {
        const userId = req.user.id;
        const gameId = req.params.id;
        await favoriteModel.removeFavorite(userId, gameId);
        res.json({ message: '移除收藏成功' });
    } catch (error) {
        res.status(500).json({ error: '移除收藏失败' });
    }
};

module.exports = {
    getFavorites,
    addFavorite,
    removeFavorite
};